

import { Component, OnInit } from '@angular/core';
import {Winner} from "../domain/Winner";
import {Bingo} from "../domain/Bingo";
import {RestService} from "../services/RestService";
import {ConfirmationService, Message} from 'primeng/primeng';

@Component({
    selector: 'page-winner',
    templateUrl: './winner.component.html',
    styleUrls: ['./winner.component.css'],
    providers: [ConfirmationService]
})
export class WinnerComponent implements OnInit{

    bingo : Bingo;

    winners : Winner [];

    msgs: Message[] = [];

    constructor(
        private restService: RestService,
        private confirmationService: ConfirmationService) {

        this.bingo = new Bingo();
    }

	ngOnInit() {
        console.log("开始查询...");
        this.restService.getCurrentBingo().then(b => {
            this.bingo = b;

            this.restService.getWinnersByBingo(this.bingo.id).then(w => {
                this.winners = w;
            })
        });
	}


	onDeleteClick(winner: Winner) {
        console.log("删除中奖记录...");

        this.confirmationService.confirm({
            message: '您是否要删除' + winner.member.name + '的中奖记录?',
            header: '删除确认',
            icon: 'fa fa-trash',
            accept: async () => {

                await this.restService.removeWinnerById(winner.id);
                this.winners = await this.restService.getWinnersByBingo(this.bingo.id);

                this.msgs = [{severity:'info', summary:'已删除', detail:'删除记录成功！'}];
            },
            reject: () => {
                this.msgs = [{severity:'info', summary:'已放弃', detail:'放弃删除记录...'}];
            }
        });
    }


	
}